import numpy as np
import math as mat
import time


def Funcao (a):
    temp=np.zeros
    temp2=np.zeros
    temp=abs(a[0])+abs(a[1])
    temp2=a[0]**2+a[1]**2
    f=(-1)*temp*mat.exp(-temp2)
    return (f)    
    
    
    
def LuusJaakola(nint , nout, raio,contrac, dimen):
    x= (-4)*np.random.rand(dimen)+(4)*np.random.rand(dimen) #gerando de -4 a 4 
    #print x
    for i in range(nout):
        for j in range(nint):
            novox=x+raio*(np.random.rand(2)-0.5)
            if Funcao(novox) < Funcao(x):
                x = novox 
        raio = (1 -contrac)*raio;
    minimo = x
    return minimo

# 0 = falso , 1 = verdadeiro 
def Iguais(a , b, epsilon):
    temp = a-b
    #print " a e b " 
    #print a , b 
    
    situacao=True
    for j in range(0,len(a)):
        #print "tempj"
        #print j 
        #print abs(temp[j]) , epsilon
        if ( abs(temp[j]) > epsilon  ):
            return False
    return situacao

        
        
    


#x = [[5], [5]]
numraizes =4 
raizes = []
temigual=0;
i=0

#print valor
#print len(raizes)

start = time.clock()

while (i<numraizes):    
    valor=LuusJaakola(10,1000,1,0.01,2)
    
    if  (len(raizes)==0):
            raizes.append(valor)            
            i=i+1
    else:
        j=0
        temigual=0

        for j in range (0, len(raizes)):
            #print "valor e raizes" 
            #print  valor , raizes[j]  
            temp = Iguais(valor, raizes[j],0.0001)
            #print temp 
            if (temp ==True ):
                #print "sao iguais" 
                #print valor , raizes[j]
                temigual=1
            
        if (temigual==0 ):
            raizes.append(valor)  
            i=i+1
       
end = time.clock()
print "Tempo de algoritmo = ", end - start, "seconds"   
    #print "vou printar" 
print raizes
         




